<!doctype html>

<html>
<head>
  <link rel="shortcut icon" href="static/images/favicon.ico" type="image/x-icon">
  <title>nodeiterator.js (Closure Library API Documentation - JavaScript)</title>
  <link rel="stylesheet" href="static/css/base.css">
  <link rel="stylesheet" href="static/css/doc.css">
  <link rel="stylesheet" href="static/css/sidetree.css">
  <link rel="stylesheet" href="static/css/prettify.css">

  <script>
     var _staticFilePath = "static/";
  </script>

  <script src="static/js/doc.js">
  </script>

  <meta charset="utf8">
</head>

<body onload="prettyPrint()">

<div id="header">
  <div class="g-section g-tpl-50-50 g-split">
    <div class="g-unit g-first">
      <a id="logo" href="index.html">Closure Library API Documentation</a>
    </div>

    <div class="g-unit">
      <div class="g-c">
        <strong>Go to class or file:</strong>
        <input type="text" id="ac">
      </div>
    </div>
  </div>
</div>

<div class="clear"></div>

<h2><a href="closure_goog_dom_nodeiterator.js.html">nodeiterator.js</a></h2>

<pre class="prettyprint lang-js">
<a name="line1"></a>// Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);
<a name="line2"></a>// you may not use this file except in compliance with the License.
<a name="line3"></a>// You may obtain a copy of the License at
<a name="line4"></a>//
<a name="line5"></a>//     http://www.apache.org/licenses/LICENSE-2.0
<a name="line6"></a>//
<a name="line7"></a>// Unless required by applicable law or agreed to in writing, software
<a name="line8"></a>// distributed under the License is distributed on an &quot;AS IS&quot; BASIS,
<a name="line9"></a>// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
<a name="line10"></a>// See the License for the specific language governing permissions and
<a name="line11"></a>// limitations under the License.
<a name="line12"></a>
<a name="line13"></a>// Copyright 2008 Google Inc. All Rights Reserved.
<a name="line14"></a>
<a name="line15"></a>/**
<a name="line16"></a> * @fileoverview Iterator subclass for DOM tree traversal.
<a name="line17"></a> *
<a name="line18"></a> */
<a name="line19"></a>
<a name="line20"></a>goog.provide(&#39;goog.dom.NodeIterator&#39;);
<a name="line21"></a>
<a name="line22"></a>goog.require(&#39;goog.dom.TagIterator&#39;);
<a name="line23"></a>
<a name="line24"></a>
<a name="line25"></a>/**
<a name="line26"></a> * A DOM tree traversal iterator.
<a name="line27"></a> *
<a name="line28"></a> * Starting with the given node, the iterator walks the DOM in order, reporting
<a name="line29"></a> * events for each node.  The iterator acts as a prefix iterator:
<a name="line30"></a> *
<a name="line31"></a> * &lt;pre&gt;
<a name="line32"></a> * &amp;lt;div&amp;gt;1&amp;lt;span&amp;gt;2&amp;lt;/span&amp;gt;3&amp;lt;/div&amp;gt;
<a name="line33"></a> * &lt;/pre&gt;
<a name="line34"></a> *
<a name="line35"></a> * Will return the following nodes:
<a name="line36"></a> *
<a name="line37"></a> * &lt;code&gt;[div, 1, span, 2, 3]&lt;/code&gt;
<a name="line38"></a> *
<a name="line39"></a> * With the following depths
<a name="line40"></a> *
<a name="line41"></a> * &lt;code&gt;[1, 1, 2, 2, 1]&lt;/code&gt;
<a name="line42"></a> *
<a name="line43"></a> * Imagining &lt;code&gt;|&lt;/code&gt; represents iterator position, the traversal stops at
<a name="line44"></a> * each of the following locations:
<a name="line45"></a> *
<a name="line46"></a> * &lt;pre&gt;&amp;lt;div&amp;gt;|1|&amp;lt;span&amp;gt;|2|&amp;lt;/span&amp;gt;3|&amp;lt;/div&amp;gt;&lt;/pre&gt;
<a name="line47"></a> *
<a name="line48"></a> * The iterator can also be used in reverse mode, which will return the nodes
<a name="line49"></a> * and states in the opposite order.  The depths will be slightly different
<a name="line50"></a> * since, like in normal mode, the depth is computed *after* the last move.
<a name="line51"></a> *
<a name="line52"></a> * Lastly, it is possible to create an iterator that is unconstrained, meaning
<a name="line53"></a> * that it will continue iterating until the end of the document instead of
<a name="line54"></a> * until exiting the start node.
<a name="line55"></a> *
<a name="line56"></a> * @param {Node} opt_node The start node.  Defaults to an empty iterator.
<a name="line57"></a> * @param {boolean} opt_reversed Whether to traverse the tree in reverse.
<a name="line58"></a> * @param {boolean} opt_unconstrained Whether the iterator is not constrained to
<a name="line59"></a> *     the starting node and its children.
<a name="line60"></a> * @param {number} opt_depth The starting tree depth.
<a name="line61"></a> * @constructor
<a name="line62"></a> * @extends {goog.dom.TagIterator}
<a name="line63"></a> */
<a name="line64"></a>goog.dom.NodeIterator = function(opt_node, opt_reversed,
<a name="line65"></a>    opt_unconstrained, opt_depth) {
<a name="line66"></a>  goog.dom.TagIterator.call(this, opt_node, opt_reversed, opt_unconstrained,
<a name="line67"></a>      null, opt_depth);
<a name="line68"></a>};
<a name="line69"></a>goog.inherits(goog.dom.NodeIterator, goog.dom.TagIterator);
<a name="line70"></a>
<a name="line71"></a>
<a name="line72"></a>/**
<a name="line73"></a> * Moves to the next position in the DOM tree.
<a name="line74"></a> * @return {Node} Returns the next node, or throws a goog.iter.StopIteration
<a name="line75"></a> *     exception if the end of the iterator&#39;s range has been reached.
<a name="line76"></a> */
<a name="line77"></a>goog.dom.NodeIterator.prototype.next = function() {
<a name="line78"></a>  do {
<a name="line79"></a>    goog.dom.NodeIterator.superClass_.next.call(this);
<a name="line80"></a>  } while (this.isEndTag());
<a name="line81"></a>
<a name="line82"></a>  return this.node;
<a name="line83"></a>};
</pre>


</body>
</html>
